/**
 * 此版本依赖了bootbox
 * http://bootboxjs.com/documentation.html#bb-dialog-options
 * @param top.$
 */
(function($) {
	bootbox.setLocale("zh_CN");
	$.extend({
		"messagebox" : {
			"alert" : function(message,level, callback) {
				var title = "消息";
				var msg  = '<h3 class="text-info"><span class="glyphicon glyphicon-info-sign"></span>&nbsp;&nbsp;%</h3>';
				if(level=="success"){
					title="成功";
					msg  = '<h3 class="text-success"><span class="glyphicon glyphicon-ok-sign"></span>&nbsp;&nbsp;%</h3>';
				}else if(level=="info"){
					title="消息";
					msg  = '<h3 class="text-info"><span class="glyphicon glyphicon-info-sign"></span>&nbsp;&nbsp;%</h3>';
				}else if(level=="warning"){
					title="警告";
					msg  = '<h3 class="text-warning"><span class="glyphicon glyphicon-warning-sign"></span>&nbsp;&nbsp;%</p>';
				}else if(level=="danger"||level=="error"){
					title="错误";
					msg  = '<h3 class="text-danger"><span class="glyphicon glyphicon-exclamation-sign"></span>&nbsp;&nbsp;%</h3>';
				}

				return top.bootbox.alert({
					"onEscape" : false,
					"closeButton" : false,
					"title" : title,
					"message" : msg.replace("%",message),
					"callback" : function() {
						if (top.$.isFunction(callback)) {
							callback();
						}
					}
				});
			},
			/**
			 * callback 参数 true 或者 false
			 */
			"confirm" : function(message, callback) {
				return top.bootbox.confirm({
					"onEscape" : false,
					"closeButton" : false,
					"title" : "请选择",
					"message" : "<h3>" + message + "</h3>",
					"callback" : function(result) {
						if (top.$.isFunction(callback)) {
							callback(result);
						}
					}
				});
			},
			/**
			 * callback 参数是 输入的字符串 或者 ""
			 */
			"prompt" : function(message, value, callback) {
				return top.bootbox.prompt({
					"onEscape" : false,
					"closeButton" : false,
					"title" : message,
					"message" : "<p>" + message + "</p>",
					"value" : value,
					"callback" : function(result) {
						if (top.$.isFunction(callback)) {
							callback(result);
						}
					}
				});
			},
			/**
			 * callback 参数 true 或者 false 或者 null
			 */
			"confirm3" : function(message, callback) {
				return top.bootbox.dialog({
					"onEscape" : false,
					"closeButton" : false,
					"title" : "请选择",
					"message" : "<h3>" + message + "</h3>",
					"buttons" : {
						"cancel" : {
							label : "取消",
							className : "btn-default",
							callback : function() {
								if (top.$.isFunction(callback)) {
									callback(null);
								}
							}
						},
						"no" : {
							label : "否",
							className : "btn-danger",
							callback : function() {
								if (top.$.isFunction(callback)) {
									callback(false);
								}
							}
						},
						"yes" : {
							label : "是",
							className : "btn-primary",
							callback : function() {
								if (top.$.isFunction(callback)) {
									callback(true);
								}
							}
						}
					}
				});
			},
			"waiting" : function(message) {
				top.window.__waiting__ = top.bootbox.dialog({
					"onEscape" : false,
					"closeButton" : false,
					"message" : ""
                    		+'<h4>'
							+'<i class="fa fa-spinner fa-pulse fa-2x fa-fw margin-bottom"></i>'
							+'&nbsp;&nbsp;'
							+message
                        	+'</h4>'
				});
				return top.window.__waiting__;
			},
			"toast" : function(content,level){
				if(level=="success"){
					top.toastr.success(content);
				}else if(level=="info"){
					top.toastr.info(content);
				}else if(level=="warning"){
					top.toastr.warning(content);
				}else if(level=="danger"||level=="error"){
					top.toastr.error(content);
				}else{
					top.toastr.success(content);
				}
			},
			"close" : function(dlg){
				dlg.modal('hide');
			},
			"waitingClose" : function(){
				if(!top.$.isEmptyObject(top.window.__waiting__)){
					top.window.__waiting__.modal('hide');
				};
			}
		}

	});
})(jQuery);